//
// Created by WYX on 2024/9/4.
//
#include <iostream>
#include  <cmath>
#include <string>
#include <vector>

// 函数用于大数相乘
std::string multiply(std::string num1, std::string num2) {
    int len1 = num1.size();
    int len2 = num2.size();
    std::vector<int> res(len1 + len2, 0);

    // 从个位开始逐位相乘
    for (int i = len1 - 1; i >= 0; i--) {
        for (int j = len2 - 1; j >= 0; j--) {
            int sum = res[i + j + 1] + (num1[i] - '0') * (num2[j] - '0');
            res[i + j + 1] = sum % 10;
            res[i + j] += sum / 10;
        }
    }

    // 将结果转换为字符串
    std::string result;
    for (int i = 0; i < res.size(); i++) {
        if (!(result.empty() && res[i] == 0)) {
            result += (res[i] + '0');
        }
    }

    return result.empty() ? "0" : result;
}

// 函数用于计算幂
std::string power(std::string base, int exponent) {
    std::string result = "1";
    while (exponent > 0) {
        if (exponent % 2 == 1) {
            result = multiply(result, base);
        }
        base = multiply(base, base);
        exponent /= 2;
    }
    return result;
}

int main() {
    std::string base = "2";
    std::string result = power(base, 1023);
    std::cout << "2^1023 = " << result << std::endl;
    std::cout<<"pow(2,1023)="<<std::to_string(pow(2,1023))<<std::endl;
    if(std::to_string(pow(2,1023))==result)
        std::cout<<"Correct!"<<std::endl;
    else
        std::cout<<"Wrong!"<<std::endl;
    return 0;
}